package wm.samsung.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import wm.samsung.main.R;

public class ordenActivity extends Activity {
	private EditText ordenText;
	private RadioButton otros;
	private EditText otrosText;
	private TextView labelOtros;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.orden);
		ordenText = (EditText) findViewById(R.id.ordenText);
		otrosText = (EditText) findViewById(R.id.otrosText);
		labelOtros = (TextView) findViewById(R.id.otros);
		otrosText.setVisibility(View.INVISIBLE);
		labelOtros.setVisibility(View.INVISIBLE);
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			String orden = bundle.getString("clave");
			ordenText.setText(orden);
		}

		Button botonRegistrarprueba = (Button) findViewById(R.id.btnIngresarprueba);
		botonRegistrarprueba.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				
				Intent intent = new Intent(	"com.google.zxing.client.android.SCAN");
				intent.putExtra("SCAN_FORMATS", "QR CODE");
				startActivityForResult(intent, 0);
			}
		});
		otros = (RadioButton) findViewById(R.id.sextoEstado);
		otros.setOnClickListener(new RadioButton.OnClickListener() {
			public void onClick(View v) {
				otrosText.setVisibility(View.VISIBLE);
				labelOtros.setVisibility(View.VISIBLE);
			}
		});
	}

	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				String contents = intent.getStringExtra("SCAN_RESULT");
				Variables.parte=contents;
				String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
				Intent i = new Intent(getBaseContext(),modeloActivity.class);
				 //i.putExtra("clavecontenido", contents);
				 startActivity(i);
				// Handle successful scan
			} else if (resultCode == RESULT_CANCELED) {
				// Handle cancel
			}
		}
	}
	
	protected void onSaveInstanceState(Bundle instanceState) {
		super.onSaveInstanceState(instanceState);
		instanceState.putInt("visualState", ordenText.getVisibility());
	}

	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		ordenText.setVisibility(savedInstanceState.getInt("visualState"));
	}
}